package com.gome.ocean.service.datax.impl;

import java.util.List;
import java.util.Map;

import org.elasticsearch.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gome.ocean.dao.datax.ISQLUploadRecordDAO;
import com.gome.ocean.dao.model.datasource.SQLUploadRecordBean;
import com.gome.ocean.service.datax.ISQLUploadRecordService;
import com.google.common.collect.Maps;

/**
 * @author zhangguoqing 2016年11月1日 上午11:07:53
 * @since 5.0.0
 */
@Service("sqlUploadRecordServiceImpl")
public class SQLUploadRecordServiceImpl implements ISQLUploadRecordService {

    private final Logger LOG = LoggerFactory.getLogger(SQLUploadRecordServiceImpl.class);

    @Autowired
    private ISQLUploadRecordDAO iSqlUploadRecordDao;

    @Override
    public boolean insertBean(SQLUploadRecordBean bean) {
        try {
            iSqlUploadRecordDao.insert(bean);
            return true;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return false;
    }

    @Override
    public boolean updateBean(SQLUploadRecordBean bean) {
        try {
            iSqlUploadRecordDao.update(bean);
            return true;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return false;
    }

    @Override
    public SQLUploadRecordBean getBeanById(Long id) {
        SQLUploadRecordBean bean;
        try {
            bean = iSqlUploadRecordDao.getBeanById(id);
            return bean;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return null;
    }

    @Override
    public List<SQLUploadRecordBean> getBeanListBySqlId(Long sqlId) {
        List<SQLUploadRecordBean> list = Lists.newArrayList();
        try {
            list = iSqlUploadRecordDao.getBeanListBySqlId(sqlId);
            return list;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return list;
    }

    @Override
    public List<SQLUploadRecordBean> getBeanListByOaId(Long oaId) {
        List<SQLUploadRecordBean> list = Lists.newArrayList();
        try {
            list = iSqlUploadRecordDao.getBeanListByOAid(oaId);
            return list;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return list;
    }

    @Override
    public SQLUploadRecordBean getDealSuccessBeanByMap(Long sqlId, String dealStatus) {
        Map<String, Object> map = Maps.newHashMap();
        try {
            map.put("sqlId", sqlId);
            map.put("dealStatus", dealStatus);
            SQLUploadRecordBean sqlRecBean = iSqlUploadRecordDao.getDealSuccessBeanByMap(map);
            if (sqlRecBean != null) {
                return sqlRecBean;
            }
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return null;
    }

}
